﻿using Microsoft.EntityFrameworkCore;
using YDT_OrderService.Domains.Interfaces;
using YDT_OrderService.Infrastructure.Data;
using YDT_OrderService.Infrastructure.Repositorys;

namespace YDT_OrderService.Infrastructure
{
    public static class DependencyInjection
    {
        public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
        {
            var connectionString = configuration.GetConnectionString("DefaultConnection");

            services.AddDbContext<OrderServiceDbContext>(options =>
                options.UseMySql(connectionString, ServerVersion.Parse("5.7"),
                    mysqlOptions =>
                    {
                        //当执行数据库迁移（Migrations）操作时，迁移代码（Migration 类）存放在哪个程序集（Assembly）中
                        mysqlOptions.MigrationsAssembly(typeof(OrderServiceDbContext).Assembly.FullName);
                    }));

            services.AddScoped<IOrderRepository, OrderRepository>();

            return services;
        }
    }
}
